package com.situ.huffman;

public class Test2 {
	public static void main(String[] args) {
		String text = "/**\r\n" + " * The <code>AlphaComposite</code> class implements basic alpha\r\n"
				+ " * compositing rules for combining source and destination colors\r\n"
				+ " * to achieve blending and transparency effects with graphics and\r\n" + " * images.\r\n"
				+ " * The specific rules implemented by this class are the basic set\r\n"
				+ " * of 12 rules described in\r\n"
				+ " * T. Porter and T. Duff, \"Compositing Digital Images\", SIGGRAPH 84,\r\n" + " * 253-259.\r\n"
				+ " * The rest of this documentation assumes some familiarity with the\r\n"
				+ " * definitions and concepts outlined in that paper.\r\n" + " *\r\n" + " * <p>\r\n"
				+ " * This class extends the standard equations defined by Porter and\r\n"
				+ " * Duff to include one additional factor.\r\n"
				+ " * An instance of the <code>AlphaComposite</code> class can contain\r\n"
				+ " * an alpha value that is used to modify the opacity or coverage of\r\n"
				+ " * every source pixel before it is used in the blending equations.\r\n" + " *\r\n" + " * <p>\r\n"
				+ " * It is important to note that the equations defined by the Porter\r\n"
				+ " * and Duff paper are all defined to operate on color components\r\n"
				+ " * that are premultiplied by their corresponding alpha components.\r\n"
				+ " * Since the <code>ColorModel</code> and <code>Raster</code> classes\r\n"
				+ " * allow the storage of pixel data in either premultiplied or\r\n"
				+ " * non-premultiplied form, all input data must be normalized into\r\n"
				+ " * premultiplied form before applying the equations and all results\r\n"
				+ " * might need to be adjusted back to the form required by the destination\r\n"
				+ " * before the pixel values are stored.";

		HuffmanTree huffmanTree = new HuffmanTree(text);
		// 压缩
		String code = huffmanTree.toCode(text);
		System.out.println(text.length() * 8);
		System.out.println(code.length());
		System.out.println("压缩比" + (double)code.length() / text.length() / 8 * 100 + "%");
		System.out.println(code);
		
		// 解压		
		String result = huffmanTree.toText(code);
		System.out.println(result);
		

	}
}
